<!--
  ~ Copyright (c) 2020 the original author or authors
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      https://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  ~ or implied. See the License for the specific language governing
  ~ permissions and limitations under the License.
  -->

<h1 mat-dialog-title>{{ 'toolbar.change_password' | translate }}</h1>
<div class="mat-body-1" mat-dialog-content>
  <form [formGroup]="form">
    <mat-form-field appearance="outline" floatLabel="always" hideRequiredMarker>
      <mat-label>{{ 'change_password.old_password' | translate }}</mat-label>
      <mat-error>
        <span>{{ 'registration.password_restriction' | translate }}</span>
      </mat-error>
      <input
        matInput
        formControlName="oldPassword"
        type="password"
        name="oldPassword"
        placeholder="{{ 'change_password.old_password' | translate }}"
        required
      />
    </mat-form-field>

    <mat-form-field appearance="outline" floatLabel="always" hideRequiredMarker>
      <mat-label>{{ 'change_password.new_password' | translate }}</mat-label>
      <mat-hint>{{ 'registration.password_restriction' | translate }}</mat-hint>
      <mat-error>
        <span>{{ 'registration.password_restriction' | translate }}</span>
      </mat-error>
      <input
        matInput
        formControlName="newPassword"
        type="password"
        name="newPassword"
        placeholder="{{ 'change_password.new_password' | translate }}"
        required
      />
    </mat-form-field>

    <mat-form-field class="sign-up-full-width" appearance="outline" floatLabel="always" hideRequiredMarker>
      <mat-label>{{ 'registration.confirm_password' | translate }}</mat-label>
      <mat-hint>{{ 'registration.password_restriction' | translate }}</mat-hint>
      <mat-error>
        <span>{{ 'registration.password_restriction' | translate }}</span>
      </mat-error>
      <input
        matInput
        formControlName="confirmPassword"
        type="password"
        name="confirmPassword"
        placeholder="{{ 'registration.confirm_password' | translate }}"
        required
      />
    </mat-form-field>

    <mat-error *ngIf="form.errors?.passwordMismatch && !form.get('confirmPassword').errors?.minlength">
      <span>{{ 'registration.password_dont_match' | translate }}</span>
    </mat-error>
  </form>
</div>
<div mat-dialog-actions>
  <button class="button-cancel" mat-flat-button (click)="onCancelClick()" cdkFocusInitial>{{ 'common.capital.cancel' | translate }}</button>
  <button color="primary" mat-flat-button (click)="onChangeClick()" [disabled]="!form.valid">
    {{ 'common.capital.change' | translate }}
  </button>
</div>
<button class="button-cross" mat-icon-button (click)="onCancelClick()">
  <mat-icon svgIcon="cross_new" inline="true"></mat-icon>
</button>
